package com.xx.controller;

import com.xx.domain.Role;
import com.xx.domain.User;
import com.xx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : 徐闯 ssm_admin
 * @Date : 2021-05-17 11:05:22
 * @Description : 实现用户操作的Controller
 **/
@Controller
@ResponseBody
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    //添加用户
    @RequestMapping("/addUser")
    public int addUser(User user){
        return userService.insertUser(user);
    }
    //删除
    @RequestMapping("/delUser")
    public int deleteUser(int uId){
        return userService.deleteUser(uId);
    }
    //批量删除
    @RequestMapping("/delAllUser")
    public  int deleteAll(int ids[]){
        return userService.deleteAll(ids);
    }
    //用户锁定和解锁
    @RequestMapping("/lockUser")
    public int lockUser(User user){
        return userService.lockUser(user);
    }
    //展示用户可选的角色
    @RequestMapping("/showRoles")
    public List<Role> showROle(int uId){
        return userService.showROle(uId);
    }
    //绑定角色
    @RequestMapping("/addRoles")
    public int addRoles(int uId,@RequestParam(value = "rList[]") int[] rList){
        System.out.println(uId+"\t"+rList);
        HashMap map = new HashMap();
        map.put("uId",uId);
        map.put("rList",rList);
        return userService.insertUserRole(map);
    }
}
